package com.handinfo.android.ui.window;


import java.io.DataInputStream;
import java.io.IOException;

import android.R.bool;
import android.graphics.Bitmap;
import android.util.Log;

import com.handinfo.android.DWGameManager;
import com.handinfo.android.core.graphics.DWFont;
import com.handinfo.android.ui.IUIWindows;
import com.handinfo.android.ui.UIWindows;
import com.handinfo.android.uicontrols.DWControlTools;
import com.handinfo.android.uicontrols.DWControlsManager;
import com.handinfo.android.uicontrols.DWListener;
import com.handinfo.android.uicontrols.controls.DWBackground;
import com.handinfo.android.uicontrols.controls.DWButton;
import com.handinfo.android.uicontrols.controls.DWCheckbox;
import com.handinfo.android.uicontrols.controls.DWComboBox;
import com.handinfo.android.uicontrols.controls.DWFrame;
import com.handinfo.android.uicontrols.controls.DWImageBox;
import com.handinfo.android.uicontrols.controls.DWListbox;
import com.handinfo.android.uicontrols.controls.DWMessageBox;
import com.handinfo.android.uicontrols.controls.DWPercentBar;
import com.handinfo.android.uicontrols.controls.DWTextbox;
import com.handinfo.android.uicontrols.controls.DWTitle;
import com.handinfo.android.utils.Tools;

public class UIAnswer  implements IUIWindows {
	private DWFrame m_Ans_Frame;
	private String m_Ansstr[] = new  String[4];
	private int m_Ans_index[];
	private DWTextbox[] m_checkBox_textBox = new DWTextbox[4];
	private DWTitle m_Ans_tit;
	private DWImageBox m_ib_close = null;//关闭
	private Bitmap m_bm_close = null;//关闭图片
	private Bitmap m_bm_bj = null;//背景图片
	private Bitmap m_datige_1 = null;//中间条
	
	private Bitmap m_cr_tit = null;//标题
	
	private Bitmap m_jindushang_2 = null;//时间条
	private Bitmap m_jinduxia_2 = null;//时间条
	private DWPercentBar m_pb = null;//时间条绘制
	
	private DWImageBox m_datige = null;
	private DWImageBox m_datige1 = null;
	
	private DWBackground m_ans_xbj_left_bg;//左侧小背景
	private DWBackground m_ans_xbj_right_bg;//右侧小背景
	
	private int Ask_index=0;
	private boolean touch = true;//触摸锁定
	private DWCheckbox m_cb[] = new DWCheckbox[4];
	
	private DWTextbox m_tb_right;
	private DWTextbox m_tb_right_down;
	private DWTextbox m_tb_right_downend;

	private DWTextbox m_tb_time_down;
	
	private byte wins = 0;//1为正确 2为错误
	private Bitmap m_win_1 = null;//正确图片
	private Bitmap m_win_2 = null;//错误图片
	private DWImageBox m_wins = null;//正确错误
	
	public int time=0;
	public int timese=3;//显示结果倒计时
	//绘制问题以及答题按钮
	public int zexp=0;
	public int zjq=0;
	public int xw=0;
	
	public int winf=0;
	public int ask=3;
	public void DrawAnswer(){
		m_Ans_Frame = new DWFrame(DWFrame.FRAME_TYPE_FULL, true);
		m_Ans_Frame.setClickClose(false);
		
		//标题
		m_Ans_tit = new DWTitle("", m_Ans_Frame);
		m_Ans_Frame.addControl(m_Ans_tit);
		DWImageBox m_tit_ima = new DWImageBox(m_cr_tit);
		m_tit_ima.setNearAnchor(m_Ans_tit, Tools.HCENTER_VCENTER, Tools.HCENTER_VCENTER, 0, 0);
		m_Ans_Frame.addControl(m_tit_ima);
		
		//叉子
		m_ib_close = new DWImageBox(m_bm_close);
		m_ib_close.setTouchZoomIn(20, 20);
		m_ib_close.setNearAnchor(m_Ans_tit, Tools.RIGHT_TOP, Tools.RIGHT_TOP, 0, 0);

		// 关闭按钮的监听
		m_ib_close.addListener(new DWListener() {

			public void OnDoubleClick() {
			}

			public void OnClick() {
				UIWindows.getInstance().m_answer.close((byte)0);
			}
		});
		m_Ans_Frame.addControl(m_ib_close);
		
		//左侧小背景
		int w = 0;
		int h = 0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			w = m_Ans_Frame.getShowWidth()/2-60;
			h = m_Ans_Frame.getShowHeight()-60;
		}else{
			w = 365;
			h = 338;
		}
		m_ans_xbj_left_bg = new DWBackground(m_bm_bj,w ,h);
		m_ans_xbj_left_bg.setNearAnchor(m_Ans_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,
				20, 30);
		
		m_ans_xbj_left_bg.setFill(true);
		
		m_Ans_Frame.addControl(m_ans_xbj_left_bg);
		
		//右侧小背景   
		int w1 = 0;
		int h1 = 0;
		int x=0;
		int jj=0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			w1 = m_Ans_Frame.getShowWidth()/2-60;
			h1 = m_Ans_Frame.getShowHeight()-60;
			x = m_Ans_Frame.getShowWidth()/2+20;
			jj =30;
		}else{
			w1 = 330;
			h1 = 338;
			x = 408;
			jj =10;
		}
		m_ans_xbj_right_bg = new DWBackground(m_bm_bj,w1,h1);
		m_ans_xbj_right_bg.setNearAnchor(m_Ans_Frame, Tools.LEFT_TOP, Tools.LEFT_TOP,
				x, 30);
		
		m_ans_xbj_right_bg.setFill(true);
		
		m_Ans_Frame.addControl(m_ans_xbj_right_bg);
		
		//活动说明
		m_tb_right = new DWTextbox("<mark c=FFEA00>"+"活动说明："+"</mark>"+  DWControlTools.CHANGE_ROW 
				+ "每次答题共"+ask+"道题目。" + DWControlTools.CHANGE_ROW +
				"中途退出将视为结束答题。");
		m_tb_right.setNearAnchor(m_ans_xbj_right_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,20,30);
		
		m_Ans_Frame.addControl(m_tb_right);
		
		
		//中间条1
		m_datige = new DWImageBox(m_datige_1);
		m_datige.setNearAnchor(m_ans_xbj_right_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
				m_ans_xbj_right_bg.getShowWidth()-m_datige_1.getWidth()>>1,30+m_tb_right.getShowHeight()+jj);
		m_Ans_Frame.addControl(m_datige);
		
		//本题奖励
		m_tb_right_down = new DWTextbox("<mark c=FFEA00>"+"本题奖励："+"</mark>"+  DWControlTools.CHANGE_ROW 
				+ "经验："+ Exp + DWControlTools.CHANGE_ROW +
				"金钱："+Gold + DWControlTools.CHANGE_ROW +
				"修为:"+Xiuwei);
		m_tb_right_down.setNearAnchor(m_ans_xbj_right_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,20, 30+m_tb_right.getShowHeight()+jj+m_datige.getShowHeight()+jj);
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			
		}else{
			m_tb_right_down.setFont(DWFont.getFont(16));
		}
		m_Ans_Frame.addControl(m_tb_right_down);
		
	
		//中间条2
//		int y3 = 0;
//		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
//			y3 = 253;
//		}else{
//			y3 = 227;
//		}
		m_datige1 = new DWImageBox(m_datige_1);
		m_datige1.setNearAnchor(m_ans_xbj_right_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,
				m_ans_xbj_right_bg.getShowWidth()-m_datige_1.getWidth()>>1,
				30+m_tb_right.getShowHeight()+jj+m_datige.getShowHeight()+jj+m_tb_right_down.getShowHeight()+jj);
		m_Ans_Frame.addControl(m_datige1);
		
		
		//答对与问题总数
		m_tb_right_downend = new DWTextbox("<mark c=FFEA00>"+"您目前分数："+"</mark>"+winf+  DWControlTools.CHANGE_ROW 
				+ "<mark c=FFEA00>"+"剩余题目数："+"</mark>" +(ask-Ask_index)+ DWControlTools.CHANGE_ROW );
		m_tb_right_downend.setNearAnchor(m_ans_xbj_right_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,20,
				30+m_tb_right.getShowHeight()+jj+m_datige.getShowHeight()+jj+m_tb_right_down.getShowHeight()+jj+m_datige1.getShowHeight()+jj);
		m_Ans_Frame.addControl(m_tb_right_downend);
		
		
		
		
		
		//问题显示
		DWTextbox m_text = new DWTextbox(Ask_index+"."+Content,
				m_ans_xbj_left_bg.getShowWidth()-40,80);
		m_text.setNearAnchor(m_ans_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,20,22);
		
		m_Ans_Frame.addControl(m_text);
		
		

//		
//		//答题随机显示
//		
		int index = 0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			index = 10;
		}
		
		for(int i=0;i<m_cb.length;i++){
		    m_cb[i] = new DWCheckbox();
			m_cb[i].setNearAnchor(m_ans_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP, 
					62, 120+i*(m_cb[i].getShowHeight()+index));//设定选择框位置
			
//			m_Ansstr[i] = m_Ansstr[i]+ m_Ans_index[i];
			
			m_checkBox_textBox[i] = new DWTextbox(m_Ansstr[m_Ans_index[i]]);
			
			m_checkBox_textBox[i].setNearAnchor(m_cb[i], Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER, 
					0,0);//设定答案位置
		}
			if(touch){
				m_cb[0].addListener(ontouch1);
				m_cb[1].addListener(ontouch2);
				m_cb[2].addListener(ontouch3);
				m_cb[3].addListener(ontouch4);
				
				m_checkBox_textBox[0].addListener(ontouch1);
				m_checkBox_textBox[1].addListener(ontouch2);
				m_checkBox_textBox[2].addListener(ontouch3);
				m_checkBox_textBox[3].addListener(ontouch4);
			}
		
		for(int i=0;i<m_cb.length;i++){
			m_Ans_Frame.addControl(m_cb[i]);
			m_Ans_Frame.addControl(m_checkBox_textBox[i]);
		}
		


		
		//剩余时间
		m_pb = new DWPercentBar(277, m_jindushang_2, m_jinduxia_2);
		m_tb_time_down = new DWTextbox(time+"秒");
		
		
		int x2=0;
		int y2=0;
		if(DWGameManager.AdpaterType == DWGameManager.AD_HIGH){
			x2 = m_ans_xbj_left_bg.getShowWidth()-(m_pb.getShowWidth()+m_tb_time_down.getShowWidth())>>1;
			y2 = m_ans_xbj_left_bg.getShowHeight()  - m_pb.getShowHeight()-50;
		}else{
			x2 = 20;
			y2 = 300;
		}
		

		m_pb.setNearAnchor(m_ans_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,x2,y2);	
		m_Ans_Frame.addControl(m_pb);

		m_tb_time_down.setNearAnchor(m_pb,Tools.LEFT_VCENTER, Tools.RIGHT_VCENTER,5,0);
		m_Ans_Frame.addControl(m_tb_time_down);
		
		
		//显示正确与错误
		

		
		switch (wins) {
		case 1:
			m_wins = new DWImageBox(m_win_1);
			m_wins.setNearAnchor(m_ans_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,0,0);
			m_Ans_Frame.addControl(m_wins);
			DWGameManager.getInstance().addSystemInfo(1, "获得经验："+Exp+" 获得金钱："+Gold + "获得修为:"+Xiuwei);
			break;
		case 2:
			m_wins = new DWImageBox(m_win_2);
			m_wins.setNearAnchor(m_ans_xbj_left_bg, Tools.LEFT_TOP, Tools.LEFT_TOP,0,0);
			m_Ans_Frame.addControl(m_wins);
			break;

		default:
			break;
		}
		
		DWControlsManager.getInstance().addControl(m_Ans_Frame);
		if(m_Intoff){
			drawInterrupt();
		}

	}
	Bitmap m_cr_but = null;
	Bitmap m_cr_but_1 = null;
	private DWFrame m_Soa_Frame;
	//结算
	public void DrawSOA(){

		
		m_Soa_Frame = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		m_Soa_Frame.m_null_frame = true;
		m_Soa_Frame.setClickClose(false);
		m_Soa_Frame.setThrough(true);
		m_Soa_Frame.setShield(true);
		final DWMessageBox mb = new DWMessageBox("答题结算", "<mark c=FFEA00>"+"答题数量："+"</mark>"+winf+"/"+ask+  DWControlTools.CHANGE_ROW 
				+ "<mark c=FFEA00>"+"获得总经验："+"</mark>" +zexp+ DWControlTools.CHANGE_ROW 
				+ "<mark c=FFEA00>"+"获得总金钱："+"</mark>" +zjq+ DWControlTools.CHANGE_ROW
				+ "<mark c=FFEA00>"+"获得总修为："+"</mark>" +xw+ DWControlTools.CHANGE_ROW
				,"确定","取消");

			mb.addListener(new DWListener(){

				public void OnDoubleClick() {
					// TODO Auto-generated method stub
					
				}

				public void OnClick() {
					// TODO Auto-generated method stub
					if(mb.getResult()==DWMessageBox.SOFTKEY_OK){
//						jinrujiesuan=true;
						winf=0;
						zexp=0;
						zjq=0;
						xw=0;
						Ask_index = 0;
						DWControlsManager.getInstance().removeControl(m_Ans_Frame);
						DWControlsManager.getInstance().removeControl(m_Soa_Frame);
					}
					if(mb.getResult()==DWMessageBox.SOFTKEY_BACK){
//						jinrujiesuan=true;
						winf=0;
						zexp=0;
						zjq=0;
						xw=0;
						Ask_index = 0;
						DWControlsManager.getInstance().removeControl(m_Ans_Frame);
						DWControlsManager.getInstance().removeControl(m_Soa_Frame);
					}
					
				}
				
			});
			m_Soa_Frame.addControl(mb);
			DWControlsManager.getInstance().addControl(m_Soa_Frame);
	}
	private DWFrame m_Interrupt_Frame;
	private boolean m_Intoff=false;
	//中断确认
	public void drawInterrupt(){
		
		m_Interrupt_Frame = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		m_Interrupt_Frame.m_null_frame = true;
		m_Interrupt_Frame.setClickClose(false);
		m_Interrupt_Frame.setThrough(true);
		m_Interrupt_Frame.setShield(true);
		final DWMessageBox mb = new DWMessageBox("提示", "是否退出答题？");
			mb.addListener(new DWListener(){

				public void OnDoubleClick() {
					// TODO Auto-generated method stub
					
				}

				public void OnClick() {
					// TODO Auto-generated method stub
					if(mb.getResult()==DWMessageBox.SOFTKEY_OK){
						Ask_index=1;
						m_Intoff=false;
						xianshi=false;
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
						DWControlsManager.getInstance().removeControl(m_Ans_Frame);
						DrawSOA();
					}
					if(mb.getResult()==DWMessageBox.SOFTKEY_BACK){
						m_Intoff=false;
						DWControlsManager.getInstance().removeControl(m_Ans_Frame);
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
						DrawAnswer();
					}
					
				}
				
			});
			m_Interrupt_Frame.addControl(mb);
			DWControlsManager.getInstance().addControl(m_Interrupt_Frame);
	}
	//二次确认
	public void drawtwoconfirmed(DataInputStream dis) throws IOException{
		
		
		
		
		byte Status = dis.readByte();// 进入状态
		//Log.e("Status", ""+Status);
		DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
		m_Interrupt_Frame = new DWFrame(DWGameManager.Screen_Width, DWGameManager.Screen_Height);
		m_Interrupt_Frame.m_null_frame = true;
		m_Interrupt_Frame.setClickClose(false);
		m_Interrupt_Frame.setThrough(true);
		m_Interrupt_Frame.setShield(true);
		if(Status==0){//不能参加
			final DWMessageBox mb = new DWMessageBox("提示", "本时段答题已结束。");
			mb.addListener(new DWListener(){

				public void OnDoubleClick() {
					// TODO Auto-generated method stub
					
				}

				public void OnClick() {
					// TODO Auto-generated method stub
					if(mb.getResult()==DWMessageBox.SOFTKEY_OK){
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
				
					
					}
					if(mb.getResult()==DWMessageBox.SOFTKEY_BACK){
					
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
						
					}
					
				}
				
				
			});
			m_Interrupt_Frame.addControl(mb);
		}else if(Status==1){//可以参加
			final DWMessageBox mb = new DWMessageBox("提示", "答题过程中玩家死亡、掉线等将视为结束答题。您确定进入答题吗？");
				mb.addListener(new DWListener(){
	
					public void OnDoubleClick() {
						// TODO Auto-generated method stub
						
					}
	
					public void OnClick() {
						// TODO Auto-generated method stub
						if(mb.getResult()==DWMessageBox.SOFTKEY_OK){
							DWControlsManager.getInstance().removeControl(UIWindows.getInstance().m_assistant.m_assistant_frame);
							DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
							DWGameManager.getInstance().getSendMessage().sendDuelAnswerGetinto2((byte)0);
						}
						if(mb.getResult()==DWMessageBox.SOFTKEY_BACK){
						
							DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
							
						}
						
					}
					
				});
				m_Interrupt_Frame.addControl(mb);
		}else{
			final DWMessageBox mb = new DWMessageBox("提示", "对不起！您当前的等级无法参加答题活动。");
			mb.addListener(new DWListener(){

				public void OnDoubleClick() {
					// TODO Auto-generated method stub
					
				}

				public void OnClick() {
					// TODO Auto-generated method stub
					if(mb.getResult()==DWMessageBox.SOFTKEY_OK){
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
					}
					if(mb.getResult()==DWMessageBox.SOFTKEY_BACK){
					
						DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
						
					}
					
				}
				
			});
			m_Interrupt_Frame.addControl(mb);
		}
			
			
			
	
			DWControlsManager.getInstance().addControl(m_Interrupt_Frame);
	}
	
	private int index = 0;
	public DWListener ontouch1 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
			
		}

		public void OnClick() {
			if(touch){
				if(m_Ans_index[0]==0){
					wins=1;
					winf++;
					zexp+=Exp;
					zjq+=Gold;
					xw+=Xiuwei;
					
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}else{
					wins=2;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}
				touch=false;
				m_cb[0].setChecked(true);
				m_cb[1].setChecked(false);
				m_cb[2].setChecked(false);
				m_cb[3].setChecked(false);
				for(int i=0;i<4;i++){
					m_cb[i].setTouch(touch);
				}
			}

		}
		
	};
	public DWListener ontouch2 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
			
		}

		public void OnClick() {
			if(touch){
				if(m_Ans_index[1]==0){
					wins=1;
					winf++;
					zexp+=Exp;
					zjq+=Gold;
					xw+=Xiuwei;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}else{
					wins=2;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}
				touch=false;
				m_cb[0].setChecked(false);
				m_cb[1].setChecked(true);
				m_cb[2].setChecked(false);
				m_cb[3].setChecked(false);
				for(int i=0;i<4;i++){
					m_cb[i].setTouch(touch);
				}
			}

		}
		
	};

	public DWListener ontouch3 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
			
		}

		public void OnClick() {
			if(touch){
				if(m_Ans_index[2]==0){
					wins=1;
					winf++;
					zexp+=Exp;
					zjq+=Gold;
					xw+=Xiuwei;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}else{
					wins=2;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}
				touch=false;
				m_cb[0].setChecked(false);
				m_cb[1].setChecked(false);
				m_cb[2].setChecked(true);
				m_cb[3].setChecked(false);
				for(int i=0;i<4;i++){
					m_cb[i].setTouch(touch);
				}
			}

		}
		
	};
	public DWListener ontouch4 = new DWListener(){

		public void OnDoubleClick() {
			// TODO Auto-generated method stub
			
		}

		public void OnClick() {
			if(touch){
				if(m_Ans_index[3]==0){
					wins=1;
					winf++;
					zexp+=Exp;
					zjq+=Gold;
					xw+=Xiuwei;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}else{
					wins=2;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
				}
				touch=false;
				m_cb[0].setChecked(false);
				m_cb[1].setChecked(false);
				m_cb[2].setChecked(false);
				m_cb[3].setChecked(true);
				for(int i=0;i<4;i++){
					m_cb[i].setTouch(touch);
				}
			}

		}
		
	};


	public void init() {
		winf=0;
		zexp=0;
		zjq=0;
		xw=0;
		// TODO Auto-generated method stub
		m_cr_tit = UIWindows.createImage("/img/newui/dati_1.gnp");
		m_cr_but = UIWindows.createImage("/img/newui/anniu_6.gnp"); // //按钮的图片
		m_cr_but_1 = UIWindows.createImage("/img/newui/anniu_6ax.gnp"); // //按钮点击后变的图片
		m_bm_close = UIWindows.createImage("/img/newui/fanhuianniu_1.gnp");
		m_bm_bj = UIWindows.createImage("/img/newui/beibaobj_1.gnp");
		m_datige_1 = UIWindows.createImage("/img/newui/datige_1.gnp");
		m_jinduxia_2 = UIWindows.createImage("/img/newui/jinduxia_2.gnp");
		m_jindushang_2 = UIWindows.createImage("/img/newui/jindushang_2.gnp");
		m_win_1 = UIWindows.createImage("/img/newui/zhegnque_1.gnp");
		m_win_2 = UIWindows.createImage("/img/newui/cuowu_1.gnp");
	}

	public void open(byte index) {
		
		m_Ans_index =  Tools.getSequence(4);
//		for(int i=0;i<m_Ans_index.length;i++){
//			Log.e("m_Ans_index"+"["+i+"]:",""+ m_Ans_index[i]);
//		}
		

		
		timese=3;
		
		time=15;
		
		wins=0;
		
		js=true;
		
		jinrujiesuan=true;
		
		xianshizhengque = false;
		Tools.debugPrintln("进入DrawAnswer");
		DrawAnswer();
//		drawtwoconfirmed();
		
		daojishi=true;
		timels=10;
		xianshi=true;
	
	}
	public boolean xianshi=false;//启动显示
	public boolean daojishi=false;//启动倒计时
	int timels =10;//临时时间
	//倒计时
	public boolean xianshizhengque=false;
	public boolean js=false;
	public void timedown(){
		if(xianshi){
			if(touch){
				if(daojishi){
					if(time>0){
						if(timels>0){
							timels--;
						}else{
							timels=10;
							time--;//答题时间
						}
					}
				}else{
					time=15;
				}
			}else{
				if(timese>0){
					if(timels>0){
						timels--;
					}else{
						timels=10;
						timese--;//展示正确错误时间
					}
				}
			}
			m_tb_time_down.setText(time+"秒");
			m_pb.setPercent((long)(time*18.4), 277);
			if(time<=0){
				if(!xianshizhengque){
					xianshizhengque=true;
					wins=2;
					touch=false;
//					Ask_index++;
					m_Intoff=false;
					DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DrawAnswer();
					
				
				}
			}
			
			if(Ask_index>=ask&&timese==0){
				if(jinrujiesuan){
					jinrujiesuan=false;
					xianshi = false;
					m_Intoff=false;
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					DWGameManager.getInstance().getSendMessage().sendDuelAnswering((byte)2, wins);
					DrawSOA();
				}
			}
			
			if(Ask_index<ask&&timese==0){
				if(js){
					js=false;
					DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
					//Tools.debugPrintln("进入发送指令11111111111111111111");
					DWControlsManager.getInstance().removeControl(m_Ans_Frame);
					//UIWindows.getInstance().m_answer.open((byte)0);
					//Tools.debugPrintln("发送指令m_role");
					DWGameManager.getInstance().getSendMessage().sendDuelAnswering((byte)1, wins);
				}
			}

		}
	
	}
	public boolean jinrujiesuan=true;
	public void close(byte index) {
		// TODO Auto-generated method stub
		//times.stop();

		m_Intoff=true;
		DWControlsManager.getInstance().removeControl(m_Ans_Frame);
		DrawAnswer();
	}

	public void dispose() {
		// TODO Auto-generated method stub
		
	}

	public void logic() {
		// TODO Auto-generated method stub
		timedown();
		//Tools.debugPrintln("进入");
	}
	/**
	 * 读取答题
	 * @param dis
	 * @throws IOException
	 */
	byte Status;//首次答题
	byte count; //题目总数当status为1时获取
	int Gold;//每道题目奖励金钱当status为1时获取
	int Exp;//每道题目奖励经验当status为1时获取 
	int Xiuwei;
	String Title;//题目
	String Content;//内容

	public void recvAnswer(DataInputStream dis) throws IOException {
		Tools.debugPrintln("进入recvAnswer");
		Status = dis.readByte();
		
		
		if(Status==0){
			count = dis.readByte();
			ask = count;
		}
		
		Gold = dis.readInt();
		Exp =  dis.readInt();
		Xiuwei = dis.readInt();
		
		Title = dis.readUTF();
		Content = dis.readUTF();
		for(int i=0;i<m_Ansstr.length;i++){
			m_Ansstr[i] = dis.readUTF();
		}
		touch=true;
			Ask_index++;
			m_Intoff=false;
		DWControlsManager.getInstance().removeControl(m_Interrupt_Frame);
		DWControlsManager.getInstance().removeControl(m_Ans_Frame);
		UIWindows.getInstance().m_answer.open((byte)0);
	}
}
